#include "Kmean.hpp"
#include <iostream>
#include <stdlib.h>

#define DATA_DIMENSION 4
#define DATA_SIZE 50

bool exists(std::vector<int> items,int item){
    for (int i = 0; i < items.size(); i++) {
        if(items[i] == item)
            return true;
    }
    return false;
}

void print(Point p){
    std::cout<<"<";
    for (int i = 0; i < p.size(); i++) {
        std::cout<<p[i]<<",";
    }
    std::cout<<">\n";
}

int main()
{
    std::vector<Point> pointArray;
    std::vector<Point > centroids;
    srand(time(0));
    for (int i = 0 ; i < DATA_SIZE ;i++){
        DATA_TYPE* arr = new DATA_TYPE[DATA_DIMENSION];
        arr[0] = rand() % 10;
        arr[1] = rand() % 10;
        arr[2] = rand() % 10;
        arr[3] = rand() % 10;
        std::vector<DATA_TYPE> point(arr,arr+4);
        pointArray.push_back(point);
        delete[] arr;
        arr = NULL;
    }

    std::vector<int> alreadySelected;
    for (int i = 0;i < NUM_OF_CLUSTERS;i++){
        int idx = rand()%DATA_SIZE;
        if (exists(alreadySelected,idx)) {
            i--;
            continue;
        }
        alreadySelected.push_back(idx);
        centroids.push_back(pointArray[idx]);
    }

    Kmean kmean(pointArray,centroids,DATA_DIMENSION);
    kmean.doKmean();

    std::cout<<"Number of Iterations:  "<<kmean.getNumOfIterations()<<std::endl;
    
    kmean.printCentroids();
    
    kmean.printClusteredPoints();
    
    
    
    return 0;
}


